package functional.lambda;

/**
 * @ClassName RecursiveFibonacci
 * @PackageName functional
 * @projectName myThread
 * @Description 
 * @Author games
 * @Date 2025/8/26 上午10:12
 * @Version 1.0
 */

/**
 * 将 Fibonacci 序列中的最后两个元素求和来产生下一个元素。
 */
public class RecursiveFibonacci {
    IntCall fib;

    RecursiveFibonacci() {
        fib = n -> n == 0 ? 0 :
                n == 1 ? 1 :
                        fib.call(n - 1) + fib.call(n - 2);
    }

    int fibonacci(int n) {
        return fib.call(n);
    }

    public static void main(String[] args) {
        RecursiveFibonacci rf = new RecursiveFibonacci();
        for (int i = 0; i <= 10; i++)
            System.out.println(rf.fibonacci(i));
    }
}
